package com.second.app.function;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author GYZ
 * <pre>
 *
 * </pre>
 */
public class Demo {

    private final Map<String, Object> map = new HashMap<>();

    protected void addSingletonFactory(String beanName, ObjectFactory<?> singletonFactory) {
        Assert.notNull(singletonFactory, "Singleton factory must not be null");
        synchronized (map) {
            System.out.println("111111111111");
        }
    }

    protected static Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean) {
        System.out.println("2222222222");
        return bean;
    }

    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        Object bean = Demo.class.newInstance();
        String beanName = "ABC";
        RootBeanDefinition mbd = null;
        Demo demo = new Demo();
        demo.addSingletonFactory(beanName, new ObjectFactory<Object>() {
            @Override
            public Object getObject() throws BeansException {
                return getEarlyBeanReference(beanName, mbd, bean);
            }
        });
    }
}
